<template>
  <div class="card">
    <div class="card-main">
      <div class="card-thumb" @mouseenter="showToggle" @mouseleave="showToggle">
        <img :src="isShow ? srcInstead : src" alt="" />
        <van-button type="info" v-show="isShow" @click="addcart"
          >添加到购物车</van-button
        >
      </div>
      <div class="card-desc">
        <p class="rate">
          <el-rate v-model="rate"></el-rate>
        </p>
        <div class="price-box">
          <s class="marketPrice">¥{{ marketPrice }}</s
          ><span
            class="sellPrice"
            style="color: rgb(0, 99, 209); font-size: 16px"
            >¥{{ sellPrice }}</span
          >
        </div>
        <p
          class="desc-content"
          style="cursor: pointer"
          @click="$router.push('/pdetails/' + detail.id)"
        >
          {{ descContent }}
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from 'vuex';
export default {
  data: () => {
    return {
      rate: 5,
      isShow: false,
    };
  },
  props: {
    detail: {
      type: Object,
    },
    src: {
      type: String,
      default:
        'https://demosc.chinaz.net/Files/DownLoad/moban/202206/moban6687/static/picture/product31.jpg',
    },
    srcInstead: {
      type: String,
      default:
        'https://demosc.chinaz.net/Files/DownLoad/moban/202206/moban6687/static/picture/product4.jpg',
    },
    marketPrice: {
      type: Number,
      default: 123,
    },
    sellPrice: {
      type: Number,
      default: 123,
    },
    descContent: {
      type: String,
      default: '这是一条商品描述信息',
    },
    bid: {
      type: String,
    },
  },
  methods: {
    showToggle() {
      this.isShow = !this.isShow;
      console.log(this.isShow);
    },
    ...mapMutations('carts', ['add']),
    addcart() {
      var obj = this.detail;
      obj.img = [].concat(this.src);

      obj.email = sessionStorage.getItem('email');
      obj.count = 1;
      this.add(obj);
    },
  },
  created() {
    console.log(this.$refs.aaa);
    this.$refs.aaa.removeAttribute('disabled');
  },
};
</script>

<style lang="scss" scoped>
.card-main {
  width: 242px;
  height: 336px;
  // background: skyblue;
  border-radius: 5px;
  margin: 10px;
  box-sizing: border-box;
  &:hover {
    border-shadow: 0 50 50px #000;
  }

  .card-thumb {
    position: relative;
    width: 100%;
    img {
      width: 100%;
    }
    .van-button {
      position: absolute;
      bottom: 6px;
      left: 50%;
      margin-left: -58px;
      // z-index: 99;
    }
    .van-button--info {
      background: rgb(0, 99, 209);
    }
  }

  .card-desc {
    display: flex;
    flex-direction: column;
    align-items: center;

    .price-box {
      width: 32%;
      display: flex;
      justify-content: space-between;

      s,
      span {
        display: block;
        height: 18px;
        line-height: 18px;
      }
    }
  }
}
</style>
